// sys-role.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, ManyToMany, JoinTable } from 'typeorm';
import { SysMenu } from './sys-menu.entity';

@Entity('sys_role')
export class SysRole {
  @PrimaryGeneratedColumn({ type: 'bigint' })
  id: number;

  @Column({ type: 'varchar', length: 64, unique: true, comment: '角色名称' })
  name: string;

  @Column({ type: 'varchar', length: 32, unique: true, comment: '角色编码' })
  code: string;

  @Column({ type: 'int', nullable: true, comment: '显示顺序' })
  sort: number;

  @Column({ type: 'boolean', default: true, comment: '角色状态' })
  status: boolean;

  @Column({ type: 'bigint', nullable: true, comment: '创建人ID' })
  create_by: number;

  @Column({ type: 'datetime', nullable: true, comment: '创建时间' })
  create_time: Date;

  @Column({ type: 'bigint', nullable: true, comment: '更新人ID' })
  update_by: number;

  @Column({ type: 'datetime', nullable: true, comment: '更新时间' })
  update_time: Date;

  @Column({ type: 'boolean', default: false, comment: '逻辑删除标识' })
  is_deleted: boolean;

  @ManyToMany(() => SysMenu)
  @JoinTable({
    name: 'sys_role_menu',
    joinColumn: { name: 'role_id' },
    inverseJoinColumn: { name: 'menu_id' },
  })
  menus: SysMenu[];
}
